﻿using GenericHtml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Data;
using WLFramework.Json;
using WLFramework.Web;

namespace SampleSite.admin.ajax.combox
{
    /// <summary>
    /// modules 的摘要说明
    /// </summary>
    public class modules : AjaxHttpHandler
    {
        private class Input
        {
            [WLFramework.Validation.Required]
            public int AppId { get; set; }
        }

        public override void OnProcessRequest(HttpContext context)
        {
            Input input;
            var errors = context.GetModel<Input>(out input);
            if (errors.Count == 0)
            {
                using (var db = new PermissionContext())
                {
                    var query = from m in db.sys_ModuleList
                                join p in db.sys_Applications on m.M_AppID equals p.A_ID
                                where p.A_State == 1 && p.A_ID == input.AppId &&
                                      m.M_Level == 1
                                select new
                                {
                                    id = m.M_ID,
                                    text = m.M_CName
                                };

                    context.Response.Write(JSON.Instance.ToJSON(query.ToList()));
                }
            }
            else
            {
                context.Response.Write("[]");
            }
        }
    }
}